﻿using CSharpDay11.Adapters.Interfaces;
using CSharpDay11.Data;
using CSharpDay11.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CSharpDay11.Adapters.Adapters
{
    public class ArtistArtAdapter : IArtistArtAdapter
    {
        public List<_ArtistViewModel> GetAllArtist()
        {
            List<_ArtistViewModel> Artists;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                Artists = db.Artists.Select(x => new _ArtistViewModel()
                {
                    ArtistId = x.ArtistId,
                    ArtistName = x.ArtistName,
                    //User = x.User,
                    UserId = x.UserId,
                    ArtWorks = x.ArtWork.Where(i => i.ArtistId == x.ArtistId).Select(i => new _ArtViewModel()
                    {
                        ArtId = i.ArtId,
                        ArtName = i.ArtName,
                        ArtUrl = i.ArtUrl,
                        ArtDesc = i.ArtDesc,
                        ArtistId = i.ArtistId
                    }).ToList()
                }).ToList();
            }
            return Artists;
        }
    }
}